package com.wn.service;

import com.common.base.BaseService;
import com.common.entity.Hotel;
import com.common.entity.Hotelroomitem;
import com.common.entity.PageParam;
import com.common.entity.Rsp;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wn.mapper.HotelRoomItemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service
public class HotelRoomItemServiceImpl implements BaseService<Hotelroomitem> {

    @Resource
    HotelRoomItemMapper hotelRoomItemMapper;


    @Override
    public PageInfo<Hotelroomitem> searchSomeByPage(PageParam<Hotelroomitem> pageParam) {
        if(!StringUtils.isEmpty(pageParam.getSuperSearchKeyWord())){
            //执行高级检索
            //分页
            PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
            //排序
            for(int i=0;i<pageParam.getOrderParams().length;i++){
                PageHelper.orderBy(pageParam.getOrderParams()[i]);
            }


            List<Hotelroomitem> newscategoryList=hotelRoomItemMapper.superSearch(pageParam.getSuperSearchKeyWord());
            PageInfo<Hotelroomitem> newshotelPageInfo = new PageInfo<Hotelroomitem>(newscategoryList);

            return newshotelPageInfo;

        }else{
            //分页
            PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
            //排序
            for(int i=0;i<pageParam.getOrderParams().length;i++){
                PageHelper.orderBy(pageParam.getOrderParams()[i]);
            }


            List<Hotelroomitem> newscategoryList=hotelRoomItemMapper.searchSomeByPage(pageParam.getModel());
            PageInfo<Hotelroomitem> newshotelPageInfo = new PageInfo<Hotelroomitem>(newscategoryList);

            return newshotelPageInfo;

        }
    }

    @Override
    public Hotelroomitem getOneById(String id) {
        return null;
    }

    @Override
    public Rsp addOne(Hotelroomitem hotelroomitem) {
        //生成随机id
        hotelroomitem.setId(UUID.randomUUID().toString().replace("-",""));
        return hotelRoomItemMapper.addOne(hotelroomitem)==1?Rsp.success("添加成功"):Rsp.fail().msg("添加失败");
    }

    @Override
    public Rsp update(Hotelroomitem hotelroomitem) {
        return hotelRoomItemMapper.update(hotelroomitem)==1?Rsp.success("修改成功"):Rsp.fail().msg("修改失败");
    }

    @Override
    public Rsp deleteLogical(Hotelroomitem hotelroomitem) {
        hotelroomitem.setDeleted("1");
        return hotelRoomItemMapper.update(hotelroomitem)==1?Rsp.success("逻辑删除成功"):Rsp.fail().msg("逻辑删除失败");
    }

    public List<Hotelroomitem> getByIdAll(String hotelid) {
        return hotelRoomItemMapper.getByIdAll(hotelid);
    }
}
